
﻿<?php
/**
 * Page used to display a list of external users files
 * Also allows for uploading new files/new versions of files.
 */
// Start the session handling system
session_start();

// Connect to the database
require_once ("../db.php");

// Only allow this for external users
if (!isset($_SESSION['uid']) || ($_SESSION['type'] != 'employee'))
    die('Not logged in as an external user');

// select all relevant projects
$sql = "SELECT * FROM projects WHERE (status='submitted' OR status='reworked'
    OR status='denied' OR status='need reworking' OR status='cleared')";

$sth = $db->prepare($sql);
$sth->execute();
$projects = $sth->fetchAll();
viewAllEvaluatedProjects($projects);


?>



<h1 style="margin-top: 40px;" class="evalProjects">Prosjekt som må bli evaluert</h1>
<table id="projectList">
    <th style="float: left">Navn på prosjekt:</th>
    <th>Status</th>
    <?php
    foreach ($projects as $row) {   // lists all the non evaluated projects
        if ($row['status'] == 'submitted' || $row['status'] == 'reworked') {    // if the projects has the right status
            echo "<tr>";                                                        // display in a table
            echo '<td style="width: 400px;" class="studentlist"><a href="#" onclick="displayMeetingProject(' . $row['id'] . ');">' . $row['title'] . '</a></td>';
            echo '<td style="color: #330066" class="studentlist">' . $row['status'] . '</td>';
            echo "</tr>";
        }
    }
    ?>
</table>



<?php
    // this displays the evalueted projects
function viewAllEvaluatedProjects($projects) { ?>
    <button id="viewDoneProjects">Vis alle ferdigvurderte prosjekter</button>
    <div class="doneProjects" style="display: none">
        <h1 class="evaluatedProjects">Evaluerte prosjekt</h1>
        <table id="projectList">
            <th style="float: left">Navn på prosjekt:</th>
            <th>Status</th>
            <?php
            foreach ($projects as $row) {   // loope trough the array with projects and find the projects with right status
                if ($row['status'] == 'denied' || $row['status'] == 'cleared') {
                    echo "<tr>";                                                //displays the projects in a table
                    echo '<td style="width: 500px;"  class="studentlist"><a href="#" onclick="displayMeetingProject(' . $row['id'] . ');">' . $row['title'] . '</a></td>';
                    echo '<td style="color: #330066" class="studentlist">' . $row['status'] . '</td>';
                    echo "</tr>";
                }
            }
            ?>
        </table>
    </div>
<?php }
?>
<script type="text/javascript">
    $("#viewDoneProjects").click(function(){    // function to display the evalueted projects
        $(".doneProjects").toggle("slow");
    });
</script>
